import { handleSearchLoading } from "@userList/search";
import { defaultTabsActiveKey, queryParams, refreshTable } from ".";
import { tableActiveKey } from "./store";
import { columns, defaultColumns } from "./table";
const searchLoading = ref(false);
const resetLoading = ref(false);
export const defaultSearchList = reactive([
  [
    {
      label: getProxyT("table239"),
      showTime: { format: "HH:mm:ss" },
      type: "rangePicker",
      model: "start_end_upload",
      placeholder: computed(() => [$t("base.startTime"), $t("base.endTime")]),
      format: "YYYY-MM-DD HH:mm:ss",
    },
    {
      label: getProxyT("table55"),
      type: "select",
      model: "aaaa",
      placeholder: getProxyT("placeholder59"),
      searchClass: "search-item-width-150",
      options: [],
      allowClear: true,
    },
    {
      label: getProxyT("table240"),
      type: "select",
      model: "bbbb",
      placeholder: getProxyT("placeholder59"),
      searchClass: "search-item-width-150",
      options: [],
      allowClear: true,
    },
    {
      label: getProxyT("table72"),
      showTime: { format: "HH:mm:ss" },
      type: "rangePicker",
      model: "start_end_check",
      placeholder: computed(() => [$t("base.startTime"), $t("base.endTime")]),
      format: "YYYY-MM-DD HH:mm:ss",
    },
    {
      label: getProxyT("table241"),
      type: "select",
      model: "cccc",
      placeholder: getProxyT("placeholder59"),
      searchClass: "search-item-width-150",
      options: [],
      allowClear: true,
    },
  ],
  [],
]);
export const searchList = ref<any>(defaultSearchList[tableActiveKey.value]);
export const tabsOptionsMap = ref([
  {
    label: "审核明细",
    value: 0,
  },
  {
    label: "审核配置",
    value: 1,
  },
]);
export const searchConfig = () => {
  const defineSearch = {
    okText: getProxyT("base.query"),
    cancelText: getProxyT("base.reset"),
    searchLoading,
    resetLoading,
    refreshTableData: async (searchParams: any, type: any) => {
      if (type === 1) {
        initObjAttr(defaultTabsActiveKey, [0, 0]);
        searchParams.status = undefined;
      }
      handleSearchLoading(true, type, defineSearch);
      await refreshTable({ ...queryParams, ...searchParams });
      handleSearchLoading(false, type, defineSearch);
    },
    tabsSlot: {
      activeKey: tableActiveKey,
      on: {
        change(tableActiveKey: any) {
          searchList.value = defaultSearchList[tableActiveKey];
          initObjAttr(columns, defaultColumns[tableActiveKey]);
          refreshTable();
        },
      },
      options: tabsOptionsMap,
    },
    searchList,
  };
  return defineSearch;
};
